package o;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import java.util.ArrayList;
import java.util.Iterator;

public class bpq {
    private final Context ˋ;
    private final String ॱ;

    public bpq(@NonNull Context context, @NonNull String str) {
        this.ˋ = context;
        this.ॱ = str;
    }

    public void ˎ() {
        Intent intent = new Intent("com.huawei.appgallery.dynamic.action.AGREEMENT_CONFIRM");
        intent.putExtra("int.version", 1);
        intent.putExtra("int.sessionId", -1);
        intent.putExtra("int.result", -1);
        intent.putExtra("String.resultDesc", "Require to sign the agreement.");
        intent.putExtra("PendingIntent.resolution", cct.ˋ(this.ˋ));
        boc.ˎ.ˋ("BroadcastHelper", "Require to sign the agreement.");
        ˊ(intent);
    }

    public void ˋ(@NonNull PendingIntent pendingIntent) {
        Intent intent = new Intent("com.huawei.appgallery.dynamic.action.INSTALL_CONFIRM");
        intent.putExtra("int.version", 1);
        intent.putExtra("int.sessionId", -1);
        intent.putExtra("int.result", -2);
        intent.putExtra("String.resultDesc", "Require to agree to download and install.");
        intent.putExtra("PendingIntent.resolution", pendingIntent);
        boc.ˎ.ˋ("BroadcastHelper", "Require to agree to download and install.");
        ˊ(intent);
    }

    public void ˏ(int i, @NonNull bqd o_bqd) {
        ˏ(i, DialogButton.CONFIRM, "Fail to download the apk files.", o_bqd);
    }

    public void ˊ(int i, @NonNull bqd o_bqd) {
        ˏ(i, 0, "Download progress.", o_bqd);
    }

    private void ˏ(int i, int i2, String str, @NonNull bqd o_bqd) {
        Intent intent = new Intent("com.huawei.appgallery.dynamic.action.DOWNLOAD_PROGRESS");
        intent.putExtra("int.version", 1);
        intent.putExtra("int.sessionId", i);
        intent.putExtra("int.result", i2);
        intent.putExtra("String.resultDesc", str);
        intent.putExtra("Bundle.state", o_bqd.ˎ());
        if (i2 != 0) {
            boc.ˎ.ˊ("BroadcastHelper", "sessionId: " + i + ", result: " + i2 + ", " + str + ", stateBuilder: " + o_bqd.ˎ().toString());
        }
        ˊ(intent);
    }

    public void ˏ(int i, @Nullable ArrayList<Uri> arrayList, @NonNull bqd o_bqd) {
        Intent intent = new Intent("com.huawei.appgallery.dynamic.action.DOWNLOAD_COMPLETED");
        intent.putExtra("int.version", 1);
        intent.putExtra("int.sessionId", i);
        intent.putExtra("int.result", 0);
        intent.putExtra("String.resultDesc", "Download completed.");
        if (arrayList != null) {
            intent.putParcelableArrayListExtra("ArrayList<Uri>.apkUris", arrayList);
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                this.ˋ.grantUriPermission(this.ॱ, (Uri) it.next(), 1);
            }
        }
        intent.putExtra("Bundle.state", o_bqd.ˎ());
        boc.ˎ.ˋ("BroadcastHelper", "sessionId: " + i + ", Download completed.");
        ˊ(intent);
    }

    public void ॱ(int i, @NonNull bqd o_bqd) {
        Intent intent = new Intent("com.huawei.appgallery.dynamic.action.INSTALL_COMPLETED");
        intent.putExtra("int.version", 1);
        intent.putExtra("int.sessionId", i);
        intent.putExtra("int.result", 200);
        intent.putExtra("String.resultDesc", "Fail to install the apk files.");
        intent.putExtra("Bundle.state", o_bqd.ˎ());
        boc.ˎ.ˊ("BroadcastHelper", "sessionId: " + i + "Fail to install the apk files. || stateBuilder: " + o_bqd.ˎ().toString());
        ˊ(intent);
    }

    public void ˎ(int i, @NonNull bqd o_bqd) {
        Intent intent = new Intent("com.huawei.appgallery.dynamic.action.INSTALL_COMPLETED");
        intent.putExtra("int.version", 1);
        intent.putExtra("int.sessionId", i);
        intent.putExtra("int.result", 0);
        intent.putExtra("String.resultDesc", "Install completed.");
        intent.putExtra("Bundle.state", o_bqd.ˎ());
        boc.ˎ.ˋ("BroadcastHelper", "sessionId: " + i + ", Install completed.");
        ˊ(intent);
    }

    private void ˊ(Intent intent) {
        intent.setPackage(this.ॱ);
        this.ˋ.sendBroadcast(intent, "com.huawei.appmarket.permission.dynamic_install");
    }
}
